/*
 * Created on Oct 5, 2003
 *
 * Mihai Postelnicu
 *
 */
package ro.gateway.aida.struts.action;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.tiles.actions.TilesAction;

import ro.gateway.aida.db.PersistenceManager;
import ro.gateway.aida.db.PersistenceToken;
import ro.gateway.aida.usr.Arbiter;
import ro.gateway.aida.usr.Perms;
import ro.gateway.aida.usr.User;
import ro.gateway.aida.usr.UserUtils;


/**
 * @author Mihai Postelnicu
 * SideBarAction
 *
 * */
public class SideBarAction extends TilesAction {
    public ActionForward execute(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response) {
        ServletContext sc = getServlet().getServletContext();
		PersistenceToken token = PersistenceManager.
						tokenLookup( sc );
        Arbiter ar = Arbiter.getManager(token);
        User user = UserUtils.getLogged(request);

        if (user == null) {
            request.setAttribute("GUEST", "yes");
        } else {
            if (ar.canDo(request, Perms.ADMIN_TOOLS))
                request.setAttribute("ADMIN_TOOLS", "yes");

            if (ar.canDo(request, Perms.OBJECT_APPROVE))
                request.setAttribute("OBJECT_APPROVE", "yes");

            if (ar.canDo(request, Perms.OBJECT_SUBMIT))
                request.setAttribute("OBJECT_SUBMIT", "yes");
        }

        return mapping.findForward("menubar");
    }
}
